package com.wolfman.socket.server.controller.impl;

import com.wolfman.socket.server.controller.PersonController;
import com.wolfman.socket.server.pojo.Person;
import com.wolfman.socket.server.service.PersonService;
import com.wolfman.socket.server.service.impl.PersonServiceImpl;

/**
 * @Title
 * @Description
 * @Author WolfMan
 * @Date 2022/11/25 12:40
 * @Email 2370032534@qq.com
 */
public class PersonControllerImpl implements PersonController {

    private static PersonService personService = new PersonServiceImpl();

    @Override
    public Object saverPerson(Person person) {
        Object message = saverPersonCheckParam(person);
        if (message != null) {
            return message;
        }
        return personService.saverPerson(person);
    }

    private Object saverPersonCheckParam(Person person) {
        if (person.getAge() == null) {
            return "invalid age";
        }
        if (person.getName() == null || "".equals(person.getName())) {
            return "invalid name";
        }
        return null;
    }

    @Override
    public Object selectPerson(Person person) {
        Object message = selectPersonCheckParam(person);
        if (message != null) {
            return message;
        }
        return personService.selectPerson(person);
    }

    private Object selectPersonCheckParam(Person person) {
        if (person.getId() == null) {
            return "invalid person id";
        }
        return null;
    }
}
